package com.haochu.novel.ui;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.example.testnovel.R;
import com.haochu.novel.util.Constants;

/**
 * @author fuhuichao
 * 2017年6月20日17:14:02
 * 小说目录
 */
public class BookCategoryActivity extends Activity {

	private ListView mBookCateGoryView;
	private List<String> catogories;
	private Bundle bundle;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		//设置无标题  
        requestWindowFeature(Window.FEATURE_NO_TITLE);  
        //设置全屏  
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
		
		setContentView(R.layout.list_book_category);
		bundle=new Bundle();
		
		// 绑定listview
		mBookCateGoryView = (ListView) findViewById(R.id.mBookCateGoryView);
		
		// 绑定目录列表数据
		catogories = BookFactory.getToShowCategories();
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, catogories);
		mBookCateGoryView.setAdapter(adapter);
		
		// 设置点击单项监听
		mBookCateGoryView.setOnItemClickListener(new onItemClickListener());
	}
	
	/**
	 * 点击单项监听
	 */
	class onItemClickListener implements OnItemClickListener{
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			bundle.putInt(Constants.RESULT_KEY_CATEGORY, position);
			setResult(Constants.RESULT_CODE_CATEGORY, new Intent().putExtras(bundle));
			finish();
		}
	}
}

